﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="0" />
    <title>FaceCat</title>
</head>
<body>
    <canvas id="mycanvas" width="1000" height="700" style="position: fixed; left: 0px; top: 0px;"/>
    <script type="text/javascript" src="facecat.js"></script>
    <script type="text/javascript">
        let canvas = document.getElementById("mycanvas"); //绘图区域
        let context = canvas.getContext("2d"); //绘图上下文
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        let gPaint = new FCPaint(); //绘图对象
        gPaint.canvas = canvas;
        scaleCanvas(gPaint);
        //判断是否移动端
        gPaint.isMobile = isMobileMode();
        if (gPaint.isMobile) {
            gPaint.scaleFactorX = 2.5;
            gPaint.scaleFactorY = 2.5;
        }
        //判断主题色
        gPaint.defaultUIStyle = "light";
        addDefaultEvent(canvas, gPaint);

        /*
        * 单元格点击事件
        * grid:表格
        * row:行
        * column:列
        * cell:单元格
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        * clicks:点击次数
        */
        gPaint.onClickGridCell = function(grid, row, column, cell, firstTouch, firstPoint, secondTouch, secondPoint, clicks){
            console.log(cell.value);
        };

        /*
         * 重置大小
         */
        let resizeAll = function () {
            try {
                canvas.width = document.documentElement.clientWidth;
                canvas.height = document.documentElement.clientHeight;
                scaleCanvas(gPaint);
                updateViewDefault(gPaint.views);
            } catch (err) {
                //alert(err);
            }
            invalidate(gPaint);
        };

        /*
        * 监听大小改变
        */
        window.onresize = function () {
            resizeAll();
        };

        /*
        * 旋转监听
        */
        window.onorientationchange = function () {
            resizeAll();
        };

        //解析加载XML
        let xml = `<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="facecat">
  <head>
          </head>
  <body>
    <div dock="fill" type="tab" selectedindex="0">
      <div name="TabPage" text="可视化生成" type="tabpage">
        <table name="Grid" text="Grid" location="50,59" size="331,235" headerheight="30">
          <tr>
            <th name="FCGridColumn" text="FCGridColumn"/>
            <th name="FCGridColumn2" text="FCGridColumn2"/>
            <th name="FCGridColumn3" text="FCGridColumn3"/>
          </tr>
          <tr>
            <td>cell1</td>
            <td>cell2</td>
            <td>cell3</td>
          </tr>
          <tr>
            <td>cell1</td>
            <td>cell2</td>
            <td>cell3</td>
          </tr>
        </table>
      </div>
      <div name="TabPage2" text="代码创建" type="tabpage"/>
    </div>
  </body>
</html>
        `;
        renderFaceCat(gPaint, xml);
        let grid = findViewByName("Grid", gPaint.views);
        for (let i = 0; i < 100; i++) {
            let row = new FCGridRow();
            grid.rows.push(row);
            for (let j = 0; j < 3; j++) {
                let cell = new FCGridCell();
                cell.value = "Cell";
                row.cells.push(cell);
            }
        }
        invalidate(gPaint);
    </script>
</body>
</html>
